package com.lufei4.chestnut.view;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.lufei4.chestnut.R;
import com.lufei4.chestnut.bean.NewsTypeColumnListBean;
import com.lufei4.chestnut.bean.NewsTypeMobileBean;
import com.lufei4.chestnut.bean.NewsTypeTitleBean;

import java.util.List;

/**
 * @ProjectName: Chestnut
 * @Package: com.lufei4.chestnut.view
 * @ClassName: NewsSettingAdapter
 * @Description: java类作用描述
 * @Author: liushijiang 15833013864@163.com
 * @CreateDate: 2020/12/30 16:55
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/12/30 16:55
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class NewsSettingAdapter2 extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    public static final int TYPE_Title = 1;
    public static final int TYPE_Account = 2;
    public static final int TYPE_List = 3;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public NewsSettingAdapter2(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_Title, R.layout.item_type_title);
        addItemType(TYPE_Account, R.layout.item_type_account);
        addItemType(TYPE_List, R.layout.item_type_list);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case TYPE_Title:
                NewsTypeTitleBean newsTypeTitleBean = (NewsTypeTitleBean) item;
                TextView textView = helper.getView(R.id.tv_name);
                textView.setText(newsTypeTitleBean.title);
                if ("消息免打扰设置".equals(newsTypeTitleBean.title)){
                    ConstraintLayout.LayoutParams layoutParam = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT,dip2px(mContext,65));
                    layoutParam.setMargins(0, dip2px(mContext,5), 0, 0);
                    helper.itemView.setLayoutParams(layoutParam);
                }
                break;
            case TYPE_Account:
                NewsTypeMobileBean newsTypeMobileBean = (NewsTypeMobileBean) item;
                if (TextUtils.isEmpty(newsTypeMobileBean.Mobile)){
                    helper.setGone(R.id.col_group_text,true);
                    helper.setGone(R.id.col_group_value,false);
                }else {
                    helper.setGone(R.id.col_group_text,false);
                    helper.setGone(R.id.col_group_value,true);
                    helper.setText(R.id.tv_tradingAccountValue, newsTypeMobileBean.Mobile);
                }
                break;
            case TYPE_List:
                NewsTypeColumnListBean.DataBean dataBean = (NewsTypeColumnListBean.DataBean) item;
                helper.setText(R.id.tv_1,dataBean.columnname);
                helper.setText(R.id.tv_2,dataBean.remark);
                break;
        }
    }
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
